import os

def decode( source = 'data.dat', stop = 10000 ):
    os.system('FPGA ' + str(1*1024*1024) + ' 400')

    lines = 0
    tags = []

    with open(source) as file:
        for line in file:
            lines += 1
            data = line.split()
            if data[0] is 'EOF' or lines > stop: break
            high = int(data[1])
            low = int(data[0])
            tag = ((high & 3) * 256 + low) << 1
            if high & 4 is 0: tag += 1
            flag = high >> 3
            tags.append((flag, tag))

    return tags